package utils

import (
	"fmt"
	"github.com/xuri/excelize/v2"
	"net/http"
)

func ReadRemoteExcelData(fileDownloadUrl string) ([][]string, error) {
	var rowData [][]string
	if fileDownloadUrl == "" {
		return rowData, nil
	}

	resp, err := http.Get(fileDownloadUrl)
	if err != nil {
		return rowData, err
	}

	f, err := excelize.OpenReader(resp.Body)
	if err != nil {
		return rowData, err
	}
	defer func() {
		if err = f.Close(); err != nil {
			fmt.Println(err)
		}
		if err = resp.Body.Close(); err != nil {
			fmt.Println(err)
		}
	}()

	rowData, err = f.GetRows("输入模板")
	if err != nil {
		return rowData, err
	}

	return rowData, nil
}
